import uvicorn
from fastapi import FastAPI

app = FastAPI()

data = ["beijing", 'sh', 'sz']

@app.get("/items/")
def read_item(start: int = 0, end: int = 2):
    return data[start: end]

'''
访问 http://127.0.0.1:8000/items/ 
>>>
[
    "beijing",
    "sh"
]


访问 http://127.0.0.1:8000/items?start=0&end=3

>>> 
[
    "beijing",
    "sh",
    "sz"
]


访问参数类型错误  http://127.0.0.1:8000/items?start=0&end=asbd
>>>
{
    "detail": [
        {
            "loc": [
                "query",
                "end"
            ],
            "msg": "value is not a valid integer",
            "type": "type_error.integer"
        }
    ]
}



当声明了 Python 类型（在上面的示例中为 int）时，它们将转换为该类型并针对该类型进行校验。

我们在上面的请求中，我们默认给了默认值，当我们没有给参数的是时候，实际就是。
'''





if __name__ == '__main__':
    uvicorn.run(app="main:app", host="127.0.0.1", port=8000, reload=True, debug=True)
